package com.example.wwk.graduationpractice.Globalutils;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wwk on 2017/4/12.
 * 活动收集器
 */

public class ActivityCollector {

    public static List<Activity> activities = new ArrayList<>();
    public static void addActivity(Activity activity) {
        activities.add(activity);
    }
    public static void removeActivity(Activity activity) {
        activities.remove(activity);
    }

    public static void finishAll() {
        if (activities != null) {
            for (Activity activity : activities) {
                if (!activity.isFinishing()) {
                    activity.finish();
                }
            }
        }
    }

    public static Activity getTopActivity() {
        Activity activity = activities.get(activities.size() - 1);
        return activity;
    }
}
